﻿using System.Configuration;
using Ycg.Logging.Configuration.ConfigurationInfos;
using Ycg.Logging.Formatters;

namespace Ycg.Logging.Configuration
{
    public class LogConfigurationManager
    {
        public static void LoadAllConfigurationInfos()
        {
            LogConfigurationSection loggingSection = (LogConfigurationSection)ConfigurationManager.GetSection("logging");
            LoadFileConfigurationInfo(loggingSection);
        }

        private static void LoadFileConfigurationInfo(LogConfigurationSection loggingSection)
        {
            if (loggingSection.FileTarget != null)
            {
                switch (loggingSection.FileTarget.Format.ToUpper())
                {
                    case "XML":
                        FileLogTargetConfigurationInfo.Instance.Format = LogFormat.Xml;
                        break;
                    case "JSON":
                        FileLogTargetConfigurationInfo.Instance.Format = LogFormat.Json;
                        break;
                    case "BINARY":
                        FileLogTargetConfigurationInfo.Instance.Format = LogFormat.Binary;
                        break;
                    default:
                        FileLogTargetConfigurationInfo.Instance.Format = LogFormat.Text;
                        break;
                }
                FileLogTargetConfigurationInfo.Instance.Path = loggingSection.FileTarget.Path;
                FileLogTargetConfigurationInfo.Instance.NameFormat = loggingSection.FileTarget.NameFormat;
            }
        }
    }
}
